package com.orangelife.mobile.individual.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.curry.android.util.ImageDownloader;
import com.curry.android.util.ImageDownloader.ImageSize;
import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;
import com.orangelife.mobile.util.StringUtil;

import java.util.List;
import java.util.Map;

public class GoodsOrderListChildrenAdapter<T> extends FatherAdapter<T> {
	private Context context;
	private List<Map<String, Object>> list;

	private ImageDownloader image = ImageDownloader.getImageDownloader();

	public GoodsOrderListChildrenAdapter(Context context,
										 List<Map<String, Object>> list, ImageView ivAllOrder,
										 TextView tvGoods, boolean isItemClick) {
		this.context = context;
		this.list = list;
	}

	public GoodsOrderListChildrenAdapter(Context context,
										 List<Map<String, Object>> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_mygoods_order_children, null);
			viewHolder.ivMyGoodsPic = (ImageView) convertView
					.findViewById(R.id.ivMyGoodsPic);
			viewHolder.tvGoodsTitle = (TextView) convertView
					.findViewById(R.id.tvGoodsTitle);
			viewHolder.tvGoodsDesc = (TextView) convertView
					.findViewById(R.id.tvGoodsDesc);
			viewHolder.tvGoodsNum = (TextView) convertView
					.findViewById(R.id.tvGoodsNum2);
			viewHolder.tvPrice = (TextView) convertView
					.findViewById(R.id.tvPrice);
			viewHolder.tvFormerPrice = (TextView) convertView
					.findViewById(R.id.tvFormerPrice);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}


		Map<String, Object> map = list.get(position);
		image.download(map.get("cover").toString(),
				viewHolder.ivMyGoodsPic,
				ImageSize.IMAGE_SIZE_EXTRA_SMALL_RECTANGLE_JPG);
		viewHolder.tvGoodsTitle.setText(map.get("title")
				.toString());
		viewHolder.tvGoodsDesc.setText(map.get("pdtDesc")
				.toString());
		viewHolder.tvGoodsNum.setText(map.get("goodsCount")
				.toString());
//		if("7".equals(map.get("orderType").toString())) {
//			viewHolder.tvPrice.setText(map.get("price").toString() + "积分");
//		} else {
			viewHolder.tvPrice.setText("¥" + map.get("price").toString());
//		}
		if (!StringUtil.isContainBlank(map.get("mkPrice")
				.toString())) {
//			if("7".equals(map.get("orderType").toString())) {
//				viewHolder.tvFormerPrice.setVisibility(View.GONE);
//			} else {
				viewHolder.tvFormerPrice.setVisibility(View.VISIBLE);
				viewHolder.tvFormerPrice.setText("¥"
						+ map.get("mkPrice").toString());
				viewHolder.tvFormerPrice.getPaint().setFlags(
						Paint.STRIKE_THRU_TEXT_FLAG);
//			}
		} else {
			viewHolder.tvFormerPrice.setVisibility(View.GONE);
		}

		return convertView;

	}

	class ViewHolder {
		private ImageView ivMyGoodsPic;
		private TextView tvGoodsTitle;
		private TextView tvGoodsDesc;
		private TextView tvGoodsNum;
		private TextView tvFormerPrice;
		private TextView tvPrice;
	}

	@Override
	public BaseAdapter setList(List<T> list) {
		this.list = (List<Map<String, Object>>) list;
		return GoodsOrderListChildrenAdapter.this;
	}

}
